package com.atguigu.gmall.web.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.feign.item.SkuDetailFeignClient;
import com.atguigu.gmall.feign.product.ProductSkuDetailFeignClient;
import com.atguigu.gmall.product.vo.SkuDetailVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;

import java.math.BigDecimal;

/**
 * @ClassName: ItemController
 * @Author: WDD
 * @CreateTime: 2022-12-08  12:24
 * @Description: 商品详情页面
 */
@Controller
public class ItemController {

    @Autowired
    SkuDetailFeignClient skuDetailFeignClient;

    @Autowired
    ProductSkuDetailFeignClient productSkuDetailFeignClient;

    //商品页详情
    @GetMapping("/{skuId}.html")
    public String itemPage(@PathVariable("skuId") Long skuId, Model model){
        Result<SkuDetailVo> skuDetailList = skuDetailFeignClient.getSkuDetailList(skuId);
        SkuDetailVo data = skuDetailList.getData();

        //分类视图
        model.addAttribute("categoryView", data.getCategoryView());
        //sku信息  基本信息＋图片列表
        model.addAttribute("skuInfo", data.getSkuInfo());
        //价格
        BigDecimal price = productSkuDetailFeignClient.getPrice(skuId).getData();
        model.addAttribute("price", price);
        //销售属性
        model.addAttribute("spuSaleAttrList", data.getSpuSaleAttrList());
        //valuesSkuJson
        model.addAttribute("valuesSkuJson", data.getValueSkuJson());
        //sku的规格  平台属性

        return "item/index";
    }
}
